home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / SATAN11.ZIP / PERL / SEVERITI.PL < prev    next >
Encoding:
Text File  |  1995-04-11  |  2.8 KB  |  111 lines

  1. #
  2. # update_severities - classify vulnerabilities.
  3. #
  4. # type is taken from the $service_info field; level is taken from the
  5. # $severity field.
  6. #
  7. # Output to: 
  8. #
  9. # $severity_type_host_info{type}{host}: all SATAN records on that topic.
  10. #
  11. # $severity_type_count{type}: number of hosts with this severity.
  12. #
  13. # $severity_host_type_info{host}{type}: all SATAN records on that topic.
  14. #
  15. # $severity_host_count{host}: number of vulnerabilities per host.
  16. #
  17. # $severity_levels{severity}: host names per severity level.
  18. #
  19. # $severity_flag: reset whenever the tables are updated. To recalculate,
  20. # invoke make_severity_info().
  21. #
  22. # Standalone usage: perl severities.pl [satan_record_files...]
  23.  
  24. sub update_severities {
  25.     if ($trusted =~ /\bANY\b/) {
  26.     $type = "other vulnerabilities" if ($type = $service_output) eq "";
  27.     if (index($severity_host_type_info{$target}{$type}, $_) < $[) {
  28.         $severity_host_type_info{$target}{$type} .= $_ . "\n";
  29.         $severity_type_host_info{$type}{$target} .= $_ . "\n";
  30.         $severity_levels{$severity}{$target} .= $_ . "\n";
  31.         $severity_host_count{$target}++;
  32.         $severity_flag = 0;
  33.     }
  34.     }
  35. }
  36.  
  37. #
  38. # Generate severities-dependent statistics.
  39. #
  40. sub make_severity_info {
  41.     local($severity, $host, %junk);
  42.  
  43.     if ($severity_flag > 0) {
  44.     return;
  45.     }
  46.     $severity_flag = time();
  47.  
  48.     print "Rebuild severity type statistics...\n" if $debug;
  49.  
  50.     for $severity (keys %severity_type_host_info) {
  51.     %junk = %{$severity_type_host_info{$severity}};
  52.     $severity_type_count{$severity} = sizeof(*junk);
  53.     }
  54. }
  55.  
  56. #
  57. # Reset all severity information
  58. #
  59. sub clear_severity_info {
  60.     %severity_host_type_info = ();
  61.     %severity_type_host_info = ();
  62.     %severity_levels = ();
  63.     %severity_host_count = ();
  64.     %severity_type_count = ();
  65.     $severity_flag = 0;
  66. }
  67.  
  68. #
  69. # Some scaffolding for stand-alone operation
  70. #
  71. if ($running_under_satan == 0) {
  72.     $running_under_satan = -1;
  73.     $debug = 1;
  74.     require 'perl/misc.pl';
  75.     warn "severities.pl running in stand-alone mode";
  76.  
  77.     #
  78.     # Sort severity information and do some counting.
  79.     #
  80.     while (<>) {
  81.     chop;
  82.     if (&satan_split($_) == 0) {
  83.         &update_severities($_);
  84.     }
  85.     }
  86.     &make_severity_info();
  87.  
  88.     print "Hosts grouped by severity\n";
  89.     for $severity (sort keys %severity_type_host_info) {
  90.        print "$severity ($severity_type_count{$severity})\n";
  91.     for (sort keys %{$severity_type_host_info{$severity}}) {
  92.         print "\t$_\n";
  93.     }
  94.     }
  95.  
  96.     print "Severities grouped by host\n";
  97.     for $host (sort keys %severity_host_type_info) {
  98.     print "$host\n";
  99.     for $type (sort keys %{$severity_host_type_info{$host}}) {
  100.         for (split(/\n/, $severity_host_type_info{$host}{$type})) {
  101.         print "\t$_\n";
  102.         }
  103.     }
  104.     }
  105. }
  106.  
  107. # UPC Code:
  108.  
  109. 1;
  110.